using System;
using Webshop20.Application.Queries.Messages;

namespace Webshop20.Application.Queries.Services
{
    public interface ICheckoutOverviewService : IService{}

    public class CheckoutOverviewService : ICheckoutOverviewService
    {
        private IGetCartService getCartService;
        private IGetCustomerInformationService getCustomerInformationService;

        public CheckoutOverviewService(IGetCartService getCartService, IGetCustomerInformationService getCustomerInformationService)
        {
            this.getCartService = getCartService;
            this.getCustomerInformationService = getCustomerInformationService;
        }


        public ISystemMessage Handle(ISystemMessage request)
        {
            var overviewRequest = (CheckoutOverviewRequest) request;
            var cartResponse =
                (GetCartResponse)
                getCartService.Handle(new GetCartRequest(null, overviewRequest.VisitiorId, overviewRequest.Date));
            var customerResponse =
                (GetCustomerInformationResponse)
                getCustomerInformationService.Handle(new GetCustomerInformationRequest(overviewRequest.VisitiorId));

            return new CheckoutOverviewResponse(cartResponse.PurchasedItems, cartResponse.SavedItems,
                                                customerResponse.Customer, customerResponse.DomainMessage, cartResponse.TotalPrice);


        }
    }
}